
#include "DemoCharacter.h"

#include "Component/LineReplicationGraphComponent.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Net/UnrealNetwork.h"

ADemoCharacter::ADemoCharacter(const FObjectInitializer& ObjectInitializer)
{
	LineComponent = CreateDefaultSubobject<ULineReplicationGraphComponent>("LineComponent");
	LineComponent->SetReplicationType(ELineReplicationType::Spatialize_Dynamic);
}

void ADemoCharacter::SetId(int32 Value)
{
	Id = Value;
	LineId = Id % 3;
	FName LineName (FString::Printf(TEXT("TestLine_%d"), LineId) );
	LineComponent->SetLine(LineName);
}

int32 ADemoCharacter::GetId() const
{
	return Id;
}

void ADemoCharacter::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	DrawDebugInfo();
	TickChangeLineId();
}

void ADemoCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME_CONDITION(ADemoCharacter, Id, COND_InitialOnly);
	DOREPLIFETIME_CONDITION(ADemoCharacter, LineId, COND_None);
}

void ADemoCharacter::DrawDebugInfo() const
{
	FVector Location = GetActorLocation() + DebugInfoStart;
	
	UKismetSystemLibrary::DrawDebugString(this, Location,
		FString::Printf(TEXT("Id = %d, LineId = %d"), Id, LineId));
}

void ADemoCharacter::TickChangeLineId()
{
	
}